	var deviceType=14;
	var todayOnlineTime = 0;
	var todayEffectTime = 0;
	$(document).ready(function(){
		$(".play-laba").tipso({
			useTitle: false,
			width: "90px",
			position: 'right'
		});
		wordLoader.init();
	});
	var wordLoader={
		programName:Request["programName"],
		unitName: Request["unitName"],
		isReview: Request["isReview"],
		tipStatus:0,
		todayCredits:0,//今日总学分
		needLoadData:false,//关闭操作指南是否需要加载数据的标志
		initresp:0,
		confirmresp:0,
		word:{},
		step:0,
		effectTime:0,
		onlineTime:0,
		sessionLearned:0,
		sessionDropped:0,
		sessionReviewed:0,
		totalWords:0,
		totallearned:0,
		totaldropped:0,
		timerIdArray: new Array(),
		restoreTimerId: undefined,
		init: function(){
			var param = {
				"programName":this.programName,
				"unitName": this.unitName,
				"isReview": this.isReview,
				"deviceType":deviceType
			};
			$.ajax({
				url:'/student/studyFlow/init',
			   	data:param,
			   	cache:false,
			   	dataType:"json",
				type:"post",
				success: function(data){
					todayOnlineTime = data.todayOnlineTime;
					todayEffectTime = data.todayEffectTime;
					//显示之前设置的皮肤
					if(data.skinCss!=undefined&&data.skinCss!=null&&data.skinCss.length>0){
						$("#"+data.skinCss).find(".div").addClass("select-img");
						$("#"+data.skinCss).siblings().find(".div").removeClass("select-img");
						$("#skinCss").attr("href","css/default/"+data.skinCss+".css");
					}
					$("#programCNName").html(data.programCNName);
					wordLoader.tipStatus=data.tipStatus;
					wordLoader.todayCredits=data.todayCredits;
					if(data.totalLearnNum==0){
						showHelp2();
					}else{
						wordLoader.getNext();
					}
				}
			});
		},
		playSound:function(){
			//清除之前未执行完的计时器
			this.pauseSound();
			if(this.restoreTimerId!=undefined){
				clearTimeout(this.restoreTimerId);
			}
			playLaba();
			playmp3(this.word.soundFile,stopLaba);
			if(wordLoader.step!=0){
				var contentArray=wordLoader.word.words;
				var len=0;
				var i=0;
				var playTime = 150;
				$("#sentenceZh").addClass("klokColor");;
				//如果标准答案显示  那卡拉OK效果就加在标准答案上  否则加在用户的答案上
				if($("#sentenceEn").css("visibility") == "visible"){
					$("#sentenceEn span").addClass("sentenceColor");
					for(var j=0;j<contentArray.length;j++){
						playTime += contentArray[j].length*80;
						var timerId = setTimeout(function(){
							$("#sentenceEn").find("span").eq(i).addClass("klokColor");
							i++;
						},playTime);
						wordLoader.timerIdArray[j] = timerId;//记录卡拉ok效果的倒计时，为了暂停卡拉ok效果使用
					}
				}else{
					$("#sentence span").addClass("sentenceColor");
					for(var j=0;j<contentArray.length;j++){
						playTime += contentArray[j].length*80;
						var timerId = setTimeout(function(){
							$("#sentence").find("span").eq(i).addClass("klokColor");
							i++;
						},playTime);
						wordLoader.timerIdArray[j] = timerId;//记录卡拉ok效果的倒计时，为了暂停卡拉ok效果使用
					}
				}
				this.restoreTimerId = setTimeout(function(){
					//如果标准答案显示  那还原标准答案卡拉ok效果  否则还原用户的答案
					if($("#sentenceEn").css("visibility") == "visible"){
						$("#sentenceEn span").removeClass("klokColor");
					}else{
						$("#sentence span").removeClass("klokColor");
					}
					$("#sentenceZh").removeClass("klokColor");
					//训练页面播放完读音显示单词选项
					if(wordLoader.step==3){
						$("#wordsTable").show();
					}
				},playTime+500);
			}
			
			/*if(wordLoader.step==0)return;
			playmp3(this.word.soundFile);
			var contentArray=wordLoader.word.words;
			var len=0;
			var i=0;
			var playTime = 150;
			$("#sentenceZh").css("color","#00bb98");
			$(".play").addClass('play-gif');
			
			for(var j=0;j<contentArray.length+1;j++){
				if(j==contentArray.length){
					playTime +=500;
					setTimeout(function(){
						$("#sentenceEn span").css("color","#fff");
						$("#sentenceZh").css("color","#fff");
						$(".play").removeClass('play-gif');
//						if($("#repeatFlag").is(":checked")&&(wordLoader.step==3)){
//							wordLoader.playSound();
//						}
					},playTime);
				}else{
					playTime += contentArray[j].length*100;
					setTimeout(function(){
						$("#sentenceEn").find("span").eq(i).css("color","#00bb98");
						i++;
					},playTime);
				}
			}*/
		},
		pauseSound: function(){ //训练页面点击单词停止卡拉OK效果
			stopLaba();
			for(var j=0;j<wordLoader.timerIdArray.length;j++){
				clearTimeout(wordLoader.timerIdArray[j]);
			}
			$("#sentenceEn span").removeClass("klokColor");
		},
		saveStatus:function(){
			var param = {
				"initResponse":this.initresp,
				"confirmResponse":this.confirmresp
			}
			$.ajax({
			   url:'/student/studyFlow/save',
			   data:param,
			   cache:false,
			   type:"post",
			   dataType:"json",
			   success: function(data){
					if(data.success){
						wordLoader.getNext();
					}
				}
			});
		},
		getNext:function(){
			$.ajax({
				url:'/student/studyFlow/next',
				data:this.requestParam,
				cache:false,
				type:"post",
				dataType:"json",
				success: function(data){
					wordLoader.word={};
					wordLoader.initresp = 0;
					wordLoader.confirmresp = 0;
					wordLoader.step = 0;
					$("#next").hide();
					$("#correct").show();
					//jQuery("#txtTip").html("组句");
					//jQuery("#rightImg").hide();
					//jQuery("#wrongImg").hide();
			   		if(data.isStudyOver){
			   			if(wordLoader.isReview=="true"||wordLoader.isReview==true){ // 智能复习
			   				var dialogR = dialog({
			   					id: 'quiztipbox',
			   					title: _System["ReviewMsg"][0],
			   					cancel: false,
			   					width: '400px',
			   					content:_System["ReviewMsg"][1],
			   					okValue: _System["Confirm"],
			   					ok: function () {
			   						wordLoader.exit();
			   					}
			   				});
			   				dialogR.showModal();
			   			}else{
			   				isExit=true;
			   				$.ajax({
			   				   url:'/student/studyFlow/exit',
			   				   data:"",
			   				   cache:false,
			   				   type:"post",
			   				   dataType:"json",
			   				   success: function(data){
			   				   }
			   				});
			   				showQuizPrompt(wordLoader.programName,deviceType,18,wordLoader.unitName,0,-1,function(){ toStudyCenter();});
			   			}
			   			return;
			   		}else{
			   			var wordInfo={
				   			wordId:data.wordId,
				   			wordIndex:data.wordIndex,
				   			example_en_US:data.example_en_US,
				   			example_zh_CN:data.example_zh_CN,
				   			words:data.words,
				   			soundFile:data.exampleSoundFile
				   		}
				   		wordLoader.word=wordInfo;
			   			wordLoader.totalviewed = parseInt(data.wordsViewed);
				   		wordLoader.sessionDropped = data.sessionDropped;
			   			wordLoader.sessionReviewed = data.sessionReviewed;
				   		wordLoader.onlineTime = data.onlineTime;
				   		wordLoader.effectTime = data.effectTime;
						
						var html1=""; 
						var wordStr = ""; 
						var tempWord="";
						var wordIndexArray = new Array();//那些位置是单词，排除标点符号
						for(var i=0;i<wordInfo.words.length;i++){
							tempWord = wordInfo.words[i];
							if(tempWord.length==1 && specChar.test(tempWord)){ // 标点符号 处理 
								html1 += "<span class='specChar'>"+tempWord+"</span>";
								wordStr +="<span class='specChar'>"+tempWord+"</span>";
							}else{ // 单词处理
								wordIndexArray.push(i);
								html1 += "<span class='span_null'></span>&nbsp;";// 
								wordStr += "<span class='word'>"+tempWord+"</span>&nbsp;";
							}
						}
						initCell(wordIndexArray);//初始化选项格子
						$("#sentenceEn").html(wordStr).css("visibility","hidden");
						$("#sentenceZh").html(wordInfo.example_zh_CN).show();
						$("#sentence").html(html1);
						$("#wordsTable").show();
				   		$("#resetBut").show();
				   		$(".cry-small").show();
				   		$("#next").hide();
				   		$(".play-laba").hide();
				   		$("#overtimeTip").hide();
				   		
				   		if(wordInfo.example_en_US.length>=50&&wordInfo.example_en_US.length<100){
				   			$(".examples-bottom-font").css("font-size","16px");
				   			$(".group-words ul li").css("font-size","16px");
				   			$(".group-words ul li span").css("font-size","16px");
				   			$(".examples-top .div_line").css("font-size","16px");
				   		}else if(wordInfo.example_en_US.length>=100){
				   			$(".examples-bottom-font").css("font-size","12px");
				   			$(".group-words ul li").css("font-size","12px");
				   			$(".group-words ul li span").css("font-size","12px");
				   			$(".examples-top .div_line span").css("font-size","12px");
				   		}
				   		$(".tipso_bubble,.top").remove();
				   		$("#examples-progress").html("<div class=\"progress-big\"><div class=\"progress-small\" id=\"strength\"></div></div>");
						$("#strength").css("width",data.strengthPer+"%");
						$("#strength").parent().attr("data-tipso","记忆强度："+data.strengthPer+"%");
						$("#strength").parent().tipso({
				            useTitle: false,
				            position: 'top'
				        });
						$("#engineGear").html(data.engineGear);//引擎档位
						$("#effectTime").html(formatTime(data.effectTime));//有效时长
						$("#onlineTime").html(formatTime(data.onlineTime));
						var effectTimePer = 0;
						if(todayOnlineTime+data.onlineTime>0){
							effectTimePer = parseInt((todayEffectTime+data.effectTime)*100/(todayOnlineTime+data.onlineTime));
						}
						$("#effectManager").html("今日有效："+formatTime(todayEffectTime+data.effectTime)+"，今日在线："+formatTime(todayOnlineTime+data.onlineTime)+"，学习效率："+effectTimePer+"%");
						$("#learnedNum").html(data.sessionLearned);
						$("#droppedNum").html(data.sessionDropped);
						$("#reviewedNum").html(data.sessionReviewed);
						$("#viewedNum").html(data.wordsViewed);
						$("#totalNum").html(data.totalWords);
						respTime.init();//只初始化，不开始，如果开始倒计时，用respTime.action()函数
						respTime.action();
			   		}
				}
			});
		},
		exit:function(){
			if(!isExit){
				isExit=true;
				$("#moment").html("系统正在存储你的学习数据请稍后……");
				$.ajax({
				   url:'/student/studyFlow/exit',
				   data:"",
				   cache:false,
				   type:"post",
				   dataType:"json",
				   success: function(data){
					   toStudyCenter();
				   }
				});
			}
		}
	}
	
	/**
		提交按钮事件
	**/ 
	function submitAnswer(){
		if(wordLoader.step == 0){//提交答案
			saveStudyTime();
			$("#resetBut").hide();
			clearTimeout(respTime.timeId);
			$(".play-laba").show();
			//$("#txtTip").html("对比");
			$("#wordsTable").hide();
			$(".cry-small").hide();
			if(checkUserSentence()){//如果组对了
				playmp3(rightSound);
				wordLoader.step = 2;
				wordLoader.initresp = 1;
				if(respTime.timeOut){//如果超时了
					wordLoader.confirmresp = 2;
				}else{
					wordLoader.confirmresp = 1;
				}
				if(respTime.timeOut){//超时了
					$("#overtimeTip").show();
					setTimeout(function(){
						$("#overtimeTip").hide();
					},2000);
				}
				$("#next").show();
//				autoNextTimeId = setTimeout(function(){
//					wordLoader.saveStatus();
//				},2000);//自动跳转
			}else{//错了
				playmp3(wrongSound);
				wordLoader.initresp = 2;
				wordLoader.step = 1;
				wordLoader.confirmresp = 0;
				$("#practise").show();
				$("#sentenceEn").css("visibility","visible");
			}
//			setTimeout(function(){
//				wordLoader.playSound();
//			},730);
		}else if(wordLoader.step==1){//第二环节：抄写
			saveStudyTime();
			//$("#txtTip").html("训练");
			$("#wordsTable").show();
			$("#delete").show();
			//$("#sentenceEn").insertAfter($("#sentenceZh"));
			//$("#sentenceEn").css("visibility","hidden");
			$("#next").hide();	
			$("#practise").hide();
			$(".play-laba").hide();
			//jQuery("#wrongImg").hide();
			resetSentence();
			wordLoader.step=3;
		}else if(wordLoader.step==2){//保存
			$("#wordsTable").hide();
			wordLoader.step=-1;
			wordLoader.saveStatus();
		}
	}
	var dialogH = undefined;
	function showHelp2(){
		dialogH = dialog({
			id: 'help',
			title: "操作指南",
			width: '802px',
			height: '480px',
			content: $("#helpDiv2").html(),
			onclose: function () {
				wordLoader.getNext();
			}
		});
		dialogH.showModal();
	}
